﻿/*
 *  Copyright 2008 Alessandro Pilotti
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU Lesser General Public License as published by
 *  the Free Software Foundation; either version 2.1 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA 
 */

using System;

namespace AlexPilotti.FTPS.Common
{
    /// <summary>
    /// Base FTP exception class.
    /// </summary>
    public class FTPException : Exception
    {
        protected FTPException()
        {
        }

        public FTPException(string Message)
            : base(Message)
        {
        }

        public FTPException(string Message, Exception innerException)
            : base(Message, innerException)
        {
        }
    }

    public class FTPReplyParseException : FTPException
    {
        private string replyText;

        public string ReplyText
        {
            get { return replyText; }
        }

        public FTPReplyParseException(string replyText)
            : base("Invalid server reply: " + replyText)
        {
            this.replyText = replyText;
        }
    }

    public class FTPProtocolException : FTPException
    {
        FTPReply reply;

        public FTPReply Reply
        {
            get { return reply; }
        }

        public FTPProtocolException(FTPReply reply) : base("Invalid FTP protocol reply: " + reply.ToString())
        {
            this.reply = reply;
        }
    }

    /// <summary>
    /// Exception indicating that a command or set of commands have been cancelled by the caller, via a callback method or event.
    /// </summary>
    public class FTPOperationCancelledException : FTPException
    {
        public FTPOperationCancelledException(string Message)
            : base(Message)
        {
        }
    }

    /// <summary>
    /// FTP exception generated by a command with a return code >= 400, as stated in RFC 959.
    /// </summary>
    public class FTPCommandException : FTPException
    {
        int errorCode;

        public int ErrorCode
        {
            get { return errorCode; }
        }

        public FTPCommandException(string Message)
            : base(Message)
        {
        }

        public FTPCommandException(string Message, Exception innerException)
            : base(Message, innerException)
        {
        }

        public FTPCommandException(FTPReply reply)
            : base(reply.Message)
        {
            this.errorCode = reply.Code;
        }
    }

    /// <summary>
    /// FTP exception related to the SSL/TLS support
    /// </summary>
    public class FTPSslException : FTPException
    {
        public FTPSslException(string Message)
            : base(Message)
        {
        }

        public FTPSslException(string Message, Exception innerException)
            : base(Message, innerException)
        {
        }
    }
}
